import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from './layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/library/libraries',
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    hidden: true,
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/library',
    component: Layout,
    meta: {
      title: "图书馆管理",
      icon: 'el-icon-reading',
    },
    name: 'library',
    children: [
      {
        path: 'libraries',
        name: 'libraries',
        component: () => import('@/views/library/libraries/index.vue'),
        meta: {
          title: "图书馆管理",
        }
      },
      {
        path: 'floors',
        name: 'floors',
        component: () => import('@/views/library/floors/index.vue'),
        meta: {
          title: "楼层管理",
        }
      },
      {
        path: 'areas',
        name: 'areas',
        component: () => import('@/views/library/areas/index.vue'),
        meta: {
          title: "区域管理",
        }
      },
      {
        path: 'seats',
        name: 'seats',
        component: () => import('@/views/library/seats/index.vue'),
        meta: {
          title: "座位管理",
        }
      }
    ]
  },
  {
    path: '/reservation',
    component: Layout,
    meta: {
      title: "预约管理",
      icon: 'el-icon-date',
    },
    name: 'reservation',
    children: [
      {
        path: 'records',
        name: 'records',
        component: () => import('@/views/reservation/records/index.vue'),
        meta: {
          title: "预约记录",
        }
      },
      {
        path: 'statistics',
        name: 'statistics',
        component: () => import('@/views/reservation/statistics/index.vue'),
        meta: {
          title: "预约统计",
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    meta: {
      title: "用户管理",
      icon: 'el-icon-user',
    },
    name: 'userManagement',
    children: [
      {
        path: 'miniprogram',
        name: 'miniprogram',
        component: () => import('@/views/user/miniprogram/index.vue'),
        meta: {
          title: "小程序用户",
        }
      },
      {
        path: 'students',
        name: 'students',
        component: () => import('@/views/user/students/index.vue'),
        meta: {
          title: "学生管理",
        }
      },
      {
        path: 'schools',
        name: 'schools',
        component: () => import('@/views/user/schools/index.vue'),
        meta: {
          title: "学校管理",
        }
      }
    ]
  },
  {
    path: '/content',
    component: Layout,
    meta: {
      title: "内容管理",
      icon: 'el-icon-document',
    },
    name: 'content',
    children: [
      {
        path: 'news',
        name: 'news',
        component: () => import('@/views/content/news/index.vue'),
        meta: {
          title: "资讯管理",
        }
      },
      {
        path: 'carousels',
        name: 'carousels',
        component: () => import('@/views/content/carousels/index.vue'),
        meta: {
          title: "轮播图管理",
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
